//
//  PublishKindsSelViewController.m
//  com.modada.new
//
//  Created by ferver7 on 2019/5/12.
//  Copyright © 2019 ferver7. All rights reserved.
//

#import "PublishKindsSelViewController.h"
#import "AppKindsModel.h"

@interface PublishKindsSelViewController ()<AxcTagTextViewDelegate>
@property(nonatomic,strong)AxcUI_TagTextView *tagTextView;
@property(nonatomic, strong)NSMutableArray *textArray;
@property(nonatomic, strong)NSMutableArray * kindsArr;

@end

@implementation PublishKindsSelViewController
- (IBAction)sureAction:(id)sender {
    if (self.tagTextView.AxcUI_allSelectedTags.count == 0) {
        [AxcUI_Toast AxcUI_showCenterWithText:@"请选择分类"];
        return;
    }
    AppKindsModel * itemModel = self.kindsArr[self.tagSel];
    self.returnBtIdBlock(self.tagTextView.AxcUI_allSelectedTags.firstObject, itemModel.ID,self.tagSel);
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    mNavitationTitle(@"分类选择");
    [self.view addSubview:self.tagTextView];
//    [self.tagTextView AxcUI_addTags:@[@"1",@"2",@"3"]];
    self.textArray = [[NSMutableArray alloc]init];
    self.kindsArr = [[NSMutableArray alloc]init];
    [self getBbsType];
}
#pragma mark - 懒加载区
- (AxcUI_TagTextView *)tagTextView{
    if (!_tagTextView) {
        _tagTextView = [[AxcUI_TagTextView alloc] init];
        _tagTextView.axcUI_Size = CGSizeMake(mScreenWidth - 30, 150);
        _tagTextView.axcUI_X = 15;
        _tagTextView.axcUI_Y = 100;
        
        AxcTagTextConfig * config = [[AxcTagTextConfig alloc]init];
        config.axcUI_tagTextFont = mTitleFont(13);
        config.axcUI_tagTextColor = [UIColor AxcUI_colorWithHexCode:@"#676767"];
        config.axcUI_tagSelectedTextColor = [UIColor whiteColor];
        config.axcUI_tagBackgroundColor = [UIColor clearColor];
        config.axcUI_tagSelectedBackgroundColor = [UIColor AxcUI_colorWithHexColor:@"#6933DB"];
        config.axcUI_tagCornerRadius = 10;
        config.axcUI_tagSelectedCornerRadius = 10;
        
        config.axcUI_tagExtraSpace = CGSizeMake(20, 7);
        
        _tagTextView.axcUI_defaultConfig= config;
        _tagTextView.axcUI_tagTextViewDelegate = self;
        _tagTextView.axcUI_scrollDirection = AxcTagViewScrollDirectionStyleVertical;
        _tagTextView.backgroundColor = [UIColor whiteColor];
    }
    return _tagTextView;
}
- (void)AxcUI_tagTextView:(AxcUI_TagTextView *)tagTextView
                didTapTag:(NSString *)tagText
                  atIndex:(NSUInteger)index
                 selected:(BOOL)selected;
{
    if (self.tagSel == index) {
        [self.tagTextView AxcUI_setTagAtIndex:self.tagSel selected:YES];
    }else{
        [self.tagTextView AxcUI_setTagAtIndex:self.tagSel selected:NO];
        self.tagSel = index;
        [self.tagTextView AxcUI_setTagAtIndex:self.tagSel selected:YES];
    }
}
-(void)getBbsType
{
    NSMutableDictionary * requestInfo = [[NSMutableDictionary alloc]init];
    [PPNetworkHelper POST:app_circle_getBbsType parameters:requestInfo success:^(id responseObject) {
        if (YJPPSUCCESS(responseObject)) {
            for (NSDictionary * infoDci in responseObject[@"data"]) {
                AppKindsModel * model = [[AppKindsModel alloc]init];
                [model setValuesForKeysWithDictionary:infoDci];
                model.ID = infoDci[@"id"];
                [self.kindsArr addObject:model];
                [self.textArray addObject:model.name];
            }
        }else{
            
        }
        [self.tagTextView AxcUI_addTags:self.textArray];
        if (self.tagSelYES) {
            [self.tagTextView AxcUI_setTagAtIndex:self.tagSel selected:YES];
        }
    } failure:^(NSError *error) {
        
    } showLoading:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
